<form action="/members/register-submit" method="post" name="form1" id="form1">
<div class="am-g dnr">
  <div class="am-u-sm-12"><p><input type="tel" style="border-radius:5px;" class="am-form-field am-radius " placeholder="手机号" name="cellphone" id="cellphone" /></p></div>
  <div class="am-u-sm-12"><p><input type="text" style="border-radius:5px;" class="am-form-field am-radius " placeholder="手机验证码" id="captcha" name="captcha" maxlength="8" /></p></div>
  <div class="am-u-sm-12" id="login_do"><p><a href="javascript:void(0);" onclick="getcaptcha()" id="manualget"><input type="button" id='getCaptcha' value="获取验证码"></a></p></div>
  <div class="am-u-sm-12"><p><input type="password" style="border-radius:5px;" class="am-form-field am-radius" placeholder="密码" name="passwd1" id="passwd1" /></p></div>
  <div class="am-u-sm-12"><p><input type="password" style="border-radius:5px;" class="am-form-field am-radius" placeholder="确认密码" name="passwd2" id="passwd2" /></p></div>
  <div class="am-u-sm-12"><p><input type="text" style="border-radius:5px;" class="am-form-field am-radius " placeholder="昵称(可不填)" name="nick_name" id="nick_name" /></p></div>
  <div class="am-u-sm-12">
     <p style=" border:1px solid #CCCCCC;border-radius:5px; padding:5px 0;">
      <label class="mr"><input type="radio" name="gender" id="gender" value="2"></label>女士<label class="mr"><input type="radio" name="gender" id="gender" value="1"></label>先生
     </p>
  </div>
  <!--<div class="am-u-sm-12"><p><input type="text" style="border-radius:5px;" class="am-form-field am-radius " placeholder="邮箱" name="email" id="email" /></p></div>-->
  <div class="am-u-sm-12">
     <p style=" padding:5px 0; font-size:12px;">
      <label><input type="checkbox" name="agreement" id="agreement" value="1" checked="checked"> <span style="color:#999;">我已阅读并同意</span><a href="#" style="color:#666;">《领彩乐道精准营销平台注册协议》</a></label>
     </p>
  </div>
  <div class="am-u-sm-12"><input type="hidden" name="level3_id" value="<?=$this->level3_id?>" /><button type="button" style=" width:100%;border-radius:5px;" class="am-btn am-btn-primary" onclick="submitform()">注册</button></div>
</div>
</form>

<script>
function getcaptcha(){
    var tel = document.getElementById("cellphone").value;
	var telReg = !!tel.match(/^(13[0-9]|15[012356789]|17[0678]|18[0-9]|14[57])[0-9]{8}$/);
	if(telReg == false){
		alert("您输入的手机号码格式有误");
		document.getElementById('cellphone').focus();
		document.getElementById('cellphone').select();
		return false;
	}
	$.ajax({
		type: "post",
		url : "/members/send-verify-code",
		dataType:'json',
		data: {'cellphone':tel},
		success: function(json){
			if(json.result == 0){
				alert("验证码获取失败，请重新获取新的验证码。");
				document.getElementById('captcha').focus();
				document.getElementById('captcha').select();
				return false;
			}else{
				time(document.getElementById("getCaptcha"));
			}
		}
	});
}

var login_do = document.getElementById('login_do');
var wait=60; 

function time(o) {
	var tel = document.getElementById("cellphone").value;
	
	if (wait == 0) { 
	    o.removeAttribute("disabled");
	    login_do.style.background = "#ec7e40";
		login_do.style.boxShadow = "0 5px 0 0 #e9717e";
		getCaptcha.style.color = "#fff";           
	    document.getElementById("login_do").innerHTML = "<p><a href='?cellphone=" + tel + "'><input id='getCaptcha' type='button' value='重新发送'></a></p>";
	    wait = 60; 
	} else { 
	    o.setAttribute("disabled", true); 
	    o.value="倒计时"+wait;
	    login_do.style.background = "#dbdbdb";
		login_do.style.boxShadow = "0 5px 0 0 #cbcbcb";
		getCaptcha.style.color = "#444"; 
	    wait--; 
	    setTimeout(function() { 
			time(o) 
	    }, 1000);
	} 
}

function submitform()
{
	if( document.form1.cellphone.value.length == 0 )
	{
		alert("手机号不能为空");
		return false;
	}
	
	if( document.form1.passwd1.value.length == 0 || document.form1.passwd2.value.length == 0 )
	{
		alert("密码不能为空");
		return false;
	}
	
	if( document.form1.passwd1.value != document.form1.passwd2.value )
	{
		alert("您输入的两次密码不一致，请重新输入");
		return false;
	}
	
	if( document.getElementById("agreement").checked === false )
	{
		alert("您需要同意《零彩精准营销平台注册协议》之后才可注册");
		return false;
	}
	
	$.ajax({
		type: "post",
		url : "/ajax/is-cellphone-available",
		dataType:'json',
		data: {'cellphone':document.form1.cellphone.value},
		success: function(json){
			if(json.result == 0)
			{
				alert("此手机号已注册，请更换手机号注册或直接登陆");
				document.getElementById('cellphone').focus();
				document.getElementById('cellphone').select();
				return false;
			}else if(json.result2 == 0)
			{
				alert("此手机号已在商家平台注册，请更换手机号注册");
				document.getElementById('cellphone').focus();
				document.getElementById('cellphone').select();
				return false;
			}else{
				$.ajax({
					type: "post",
					url : "/ajax/check-vcode",
					dataType:'json',
					data: {'cellphone':document.form1.cellphone.value,'captcha':document.form1.captcha.value},
					success: function(json){
						if(json.result == 0)
						{
							showpop("您输入的短信验证码不正确或超过30分钟，请重新填写或生成新验证码");
							document.getElementById('captcha').focus();
							document.getElementById('captcha').select();
							return false;
						}else{
							form1.submit();
						}
					}
				});
			}
		}
	});
}
</script>